﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight;
using System.Linq;


namespace AR.Entities
{
    public class CSVCandidat : Entity
    {
         private int _numeroLigne;

         public int NumeroLigne
         {
             get
             {
                 return _numeroLigne;
             }
             set
             {
                 _numeroLigne = value;
                 RaisePropertyChanged("NumeroLigne");

             }
         }
        
        private string _source;
        
        public string Source
        {
            get
            {
                return _source;
            }
            set
            {
                _source = value;
                RaisePropertyChanged("Source");

            }
        }
        private string _nom;
        [Required(ErrorMessage = "Requis")]
        public global::System.String Nom
        {
            get
            {
                return _nom;
            }
            set
            {
                _nom = value.ToUpper();
                RaisePropertyChanged("Nom");

            }
        }


        private string _prenom;
        [Required(ErrorMessage = "Requis")]
        public string Prenom
        {
            get
            {
                return _prenom;
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    _prenom = value;
                else
                    _prenom = value.First().ToString().ToUpper() + value.Substring(1);

                RaisePropertyChanged("Prenom");

            }
        }
        private string _niveauEtudes;

        [Required(ErrorMessage = "Requis")]
        public string NiveauEtudes
        {
            get
            {
                return _niveauEtudes;
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    _niveauEtudes = value;
                else
                    _niveauEtudes = value.First().ToString().ToUpper() + value.Substring(1);

                RaisePropertyChanged("NiveauEtudes");
            }
        }
        private int _idEtudes;
        [Required(ErrorMessage = "Requis")]
        [RegularExpression(@"^[1-9]\d*$", ErrorMessage = "Veuillez sélectionner une valeur dans la liste (Niveau Etudes)")]
        public int IdEtudes
        {
            get
            {
                return _idEtudes;
            }
            set
            {
                _idEtudes = value;
                RaisePropertyChanged("IdEtudes");
            }
        }
        private int _idExp;
        [Required(ErrorMessage = "Requis")]
        [RegularExpression(@"^[1-9]\d*$", ErrorMessage = "Veuillez sélectionner une valeur dans la liste (Niveau Expérience)")]
        public int IdExp
        {
            get
            {
                return _idExp;
            }
            set
            {

                _idExp = value;


                RaisePropertyChanged("IdExp");
            }
        }
        private string _niveauExp;
        
        public string NiveauExp
        {
            get
            {
                return _niveauExp;
            }
            set
            {
                _niveauExp = value;
                RaisePropertyChanged("NiveauExp");

            }
        }
        
        private int? _salaire_Actuelle;
        [RegularExpression(@"^[0-9]\d*$", ErrorMessage = "Salaire Invalide")]
        public int? Salaire_Actuelle
        {
            get
            {
                return _salaire_Actuelle;
            }
            set
            {
                _salaire_Actuelle = value;
                RaisePropertyChanged("Salaire_Actuelle");

            }
        }
        private int? _salaire_Demande;
        [RegularExpression(@"^[0-9]\d*$", ErrorMessage = "Salaire Invalide")]
        public int? Salaire_Demande
        {
            get
            {
                return _salaire_Demande;
            }
            set
            {
                _salaire_Demande = value;
                RaisePropertyChanged("Salaire_Demande");

            }
        }

        private int? _preavis;
        [Required(ErrorMessage = "Requis")]
        [RegularExpression(@"^[0-9]\d*$", ErrorMessage = "Préavis Invalide")]
        public int? Preavis
        {
            get
            {
                return _preavis;
            }
            set
            {
                _preavis = value;
                RaisePropertyChanged("Preavis");

            }
        }

      
    

        private string _email;
        [Required(ErrorMessage = "Requis")]
        [RegularExpression(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$"
            , ErrorMessage = "Format Email Invalide")]
        public global::System.String Email
        {
            get
            {
                return _email;
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    _email = value;
                else
                    _email = value.ToLower();
                RaisePropertyChanged("Email");
            }
        }
        private string _tel;
        [Required(ErrorMessage = "Requis")]
        [RegularExpression(@"\d{10}", ErrorMessage = "Format Invalide(ex:0615478945)")]
        public string Tel
        {
            get
            {
                return _tel;
            }
            set
            {
                _tel = value;
                RaisePropertyChanged("_tel");

            }
        }
        private DateTime?  _dateTestTechnique;
        [Required(ErrorMessage = "Requis")]
        //[RegularExpression(@"\d{10}", ErrorMessage = "Format Invalide(ex:0615478945)")]
        public DateTime? DateTestTechnique
        {
            get
            {
                return _dateTestTechnique;
            }
            set
            {
                _dateTestTechnique = value;
                RaisePropertyChanged("DateTestTechnique");

            }
        }
     
        public bool ValidateCandidat(ValidationContext validationContext)
        {
            //Clear Previous valiadtion.
            ValidationErrors.Clear();

            IDictionary<object, object> dictionaryItems = null;
            ValidationContext employeeValidationContext = new ValidationContext(this, validationContext, dictionaryItems);
            ICollection<ValidationResult> employeeValidationResults = new List<ValidationResult>();

            //Use tryValidateobject to validate
            if (Validator.TryValidateObject(this, employeeValidationContext, employeeValidationResults, true) == false)
            {
                //Adding Validation result to validation error
                foreach (ValidationResult validationError in employeeValidationResults)
                {
                    ValidationErrors.Add(validationError);
                }
                return false;
            }

            return true;
        }
   
      
        
    }
}
